import React, {Component} from 'react';
import { NavLink } from 'react-router-dom';
import { Input,Space,Button ,Divider,message, Modal} from 'antd';

import './addManeger.css'
import axios from "../../utils/http"
import { UserOutlined,UnlockOutlined } from '@ant-design/icons';
import { EyeInvisibleOutlined, EyeTwoTone,BulbOutlined } from '@ant-design/icons';
const { confirm } = Modal;
export default class AddManeger extends Component {
    constructor(props) {
        super(props);
        this.state = {
            user:'',
            pwd:'',
        };
    }
    userText=(e)=>{
        this.setState({
            user:e.target.value
        })
    }
    pwdText=(e)=>{
        this.setState({
            pwd:e.target.value
        })
    }
  addManeger=()=>{
      let that=this
      axios.post('/mm-power/administrators/addAdministrators',{
          "adminUsername":this.state.user,
          "adminPassword":this.state.pwd
      }).then(data=>{
         if(data.data.code){
             new Promise((resolve, reject) => {

                     message.success('添加成功')
                     this.setState({
                         pwd:'',
                         user:''
                     })
                     resolve(200)


             }).then(data=>{
                 setTimeout(()=>{
                     confirm({
                         title: '您是否需要回到管理员管理界面',
                         icon:<BulbOutlined />,

                         onOk() {
                             that.props.history.push('/Home/quanXian/Maneger')
                         },
                         onCancel() {
                             console.log('Cancel');
                         },
                     });
                 },2000)

             })


         }else{
             message.error('添加失败')
         }

      })
  }
    render() {
        return (
            <div className='addManege'>
                <div className='biaoTi'>
                    <NavLink to='/Home/quanXian/Maneger'><span className='xiaoWei'>管理</span></NavLink>
                    <NavLink to='/Home/quanXian/AddManeger'><span className='spanT xiaoWei' >添加管理员</span></NavLink>
                </div>

                <div className='kuang'>
                    <div className='wen'>用户名</div>
                    <Input size="large" value={this.state.user}
                           onChange={this.userText}
                           placeholder="请输入用户名" prefix={<UserOutlined />} />


                    <br/>
                    <Space direction="vertical">

                        <div className='wen'>密码</div> <Input.Password
                        onChange={this.pwdText}
                        value={this.state.pwd}
                        placeholder="请输入密码"
                        prefix={<UnlockOutlined />}
                        iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
                    />
                    </Space>
                    <Divider></Divider>
                    <Button type="primary" onClick={this.addManeger}>确认</Button>

                </div>


            </div>
        )
    }
}